// pages/instore/index.js
let app = getApp()

Page({

    /**
     * 页面的初始数据
     */
    data: {
        tableData: [],
        option1: [
            {text: '全部', value: ''},
            {text: '生产入库', value: 1},
            {text: '退货入库', value: 2},
        ],
        queryParam: {
            pageNum: 1,
            pageSize: app.globalData.pageSize
        },
        //日历
        calendarShow: false,
        calendarDate: "",
        minDate: new Date(2022, 3, 1).getTime(),
        startDate: "",
        endDate: "",
        //入库类型 1-采购单 2-采购退货入库
        type: '',
        //collapse展开索引
        collapseIndex: []
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            spinShow: true,
            queryParam: {},
        });
        this.queryData(true)
    },
    queryData: function (override) {
        let _this = this
        app.formGet('/app/stock/recordWithCargo', this.data.queryParam).then(res => {
            _this.setData({
                spinShow: false
            });
            wx.stopPullDownRefresh()
            if (res.code === 0) {
                _this.setData({
                    tableData: override ? res.data.list : this.data.tableData.concat(res.data.list)
                });
            } else {
                app.message(res.message, 'error')
            }
        }).catch(e => {
            _this.setData({
                spinShow: false
            });
            app.message(e, 'error')
        })
    },
    // dropdown
    onChange() {
        this.queryData(true)
    },
    onConfirm() {
        this.selectComponent('#item').toggle()
        this.queryData(true)
    },

    collapseOnChange(event) {
        this.setData({
            collapseIndex: event.detail,
        });
    },
    onSearch() {
        this.setData({
            queryParam: {
                pageNum: 1,
                pageSize: app.globalData.pageSize,
                searchVal: this.data.searchVal
            },
        });
        this.queryData(true);
    },
})